import axios from 'axios'
import utilsFunc from '../api/utilsFunc';
const talentList = `${utilsFunc.baseurl}/talent/list`
const getTalentList= (params, dispatch)=>{
           return async (dispatch)=>getList(params,dispatch);
}

function getList(params,dispatch){
    let paramsStr = '';
    for(var key in params){
        var value = params[key]
        paramsStr = paramsStr + `${key}=${value}&`
    }
    paramsStr = paramsStr.slice(0,paramsStr.length-1);
    const listParams = `${talentList}?${paramsStr}`
        axios.get(listParams).then(res=>{
            dispatch(getListAction(res.data.data))
        })
}
function getListAction(talentListArr){
    return {
        type: 'GET_LIST',
        talentListArr: talentListArr
    }
}

export const mapStateToProps=(state) =>{
    return {
       talentState: state.talentState,
    }
}
export const mapDispatchToProps = (dispatch) => {
    return {
        getTalent: (params) => {
        dispatch(getTalentList(params,dispatch));
      }
    };
  }